from customExceptions import VarNotFoundExcpt

class environment:
	def __init__(self, bindingName, bindingValue, env=None):
		self.bindingName = bindingName
		self.bindingValue = bindingValue
		self.nextEnv = env
        
	def getVarRef(self,name):
	#	print "Env Target: \"", name, "\" Current Binding: ", self.bindingName
	#	print "Next Env: ", str(self.nextEnv)
		if (name == self.bindingName):
			return self.bindingValue
		elif(self.nextEnv != None):
			return self.nextEnv.getVarRef(name)
		else:
			raise VarNotFoundExcpt(name)
	
	def mutateVarRef(self, name, value):
		#print "Env_ looking for ", name, " against bindingname ", self.bindingName
		if (name == self.bindingName):
			self.bindingValue = value
		elif(self.nextEnv != None):
			return self.nextEnv.mutateVarRef(name, value)
		else:
			raise VarNotFoundExcpt(name)
                
	def __str__(self):
		return "[" + str(self.bindingName) + ":" + str(self.bindingValue) + "] " + (str(self.nextEnv),"")[self.nextEnv==None] 

class expression:
	def evaluate(self, env):
		print "don't call on base class"
	
	def traverse(self, helper):
		print "don't traverse on base class"
                
class value(expression):
	def evalutate(self):
		print "don't call base class types"
	def returnType(self):
		print "don't call base class types"
                


